package ru.autofan.action;

import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

import ru.autofan.form.LoginForm;
import ru.autofan.logic.LoginService;

public class LoginAction extends AbstractAction {

	public Event login(RequestContext context) throws Exception {
		LoginForm form = (LoginForm) getFormObject(context);
		boolean result = getService(LoginService.class).login(
				form.getLogin(), form.getPassword());
		if (!result) {
		    getFormErrors(context).reject("label.invalidEmailOrPassword", "");
		}
		return result ? success() : error();
	}
	
	public Event logout(RequestContext context) throws Exception {
		getService(LoginService.class).logout();
		return success();
	}

}
